#include<bits/stdc++.h>
using namespace std;

struct Tree{
    const static int N = 10010;
    struct edge{
        int to, nxt;
    }e[N << 1];
    int head[N], dis[N], vis[N];
    int n, len;

    Tree(){n = 0; len = 0; memset(head, 0, sizeof(head)); }

    void add_edge(int u, int v){
        e[++len].to = v; e[len].nxt = head[u]; head[u] = len; return ;
    }

    void insert_edge(int u, int v){
        add_edge(u, v); add_edge(v, u);
    }

    void dfs_get_distance(int cur, int fa){
        vis[cur] = 1;
        dis[cur] = dis[fa] + 1;
        for(int i = head[cur]; i; i = e[i].nxt){
            int to = e[i].to;
            if(!vis[to]){
                dfs_get_distance(to, cur);
            }
        }
        return ;
    }

    int get_diameter(){
        memset(vis, 0, sizeof(vis));
        memset(dis, 0, sizeof(dis));
        dis[0] = -1;
        dfs_get_distance(1, 0);
        int x = 1;
        for(int i = 1; i <= n; i++){
            if(dis[x] <= dis[i]) x = i;
        }
        memset(vis, 0, sizeof(vis));
        memset(dis, 0, sizeof(dis));
        dis[0] = -1;
        dfs_get_distance(x, 0);
        int y = 1;
        for(int i = 1; i <= n; i++){
            if(dis[y] <= dis[i]) y = i;
        }
        return dis[y];
    }
}tree;

void init(){
    scanf("%d", &tree.n);
    for(int i = 1; i < tree.n; i++){
        int u, v;
        scanf("%d%d", &u, &v);
        tree.insert_edge(u, v);
    }
    return ;
}

void solve(){
    printf("%d\n", tree.get_diameter());
    return ;    
}

int main(){
    init();
    solve();
    return 0;
}